classdef dotsDrawable < dotsAllManagedObjects
    % @class dotsDrawable
    % Superclass for drawable graphics objects.
    %
    % @ingroup drawable
    
    properties (SetObservable = true)
        % true or false, whether to draw() this object
        isVisible;
        
        % foreground color, [L], [LA], [RGB], or [RGBA], in [0-255]
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        foregroundColor;
        
        % a background color, [L] [LA] [RGB] [RGBA], 0-255
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        backgroundColor;
    end
    
    properties (SetObservable = false)
        % Psychtoolbox Screen index of the current drawing window
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        windowNumber;
        
        % pixel dimensions of the current drawing window [x y x2 y2]
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        windowRect;
        
        % Hz frame rate of the current drawing window
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        windowFrameRate;
        
        % degrees-to-pixels factor for the current drawing window
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        pixelsPerDegree;
        
        % system path to locate image files
        % Use dotsTheMachineConfiguration to specify a machine-specific
        % imagesPath.
        imagesPath;
    end
    
    methods
        % Constructor takes no arguments.
        function self = dotsDrawable
            self = self@dotsAllManagedObjects;
            
            % share drawing-related properties
            self.isVisible = true;
            dotsTheSwitchboard.sharePropertyOfObject('isVisible', self);
            dotsTheSwitchboard.sharePropertyOfObject('foregroundColor', self);
            dotsTheSwitchboard.sharePropertyOfObject('backgroundColor', self);
            
            % shared certain screen-related properties
            theScreen = dotsTheScreen.theObject;
            dotsTheSwitchboard.shareManyPropertiesOfObject( ...
                theScreen.sharedProperties, self);
        end
        
        % Do any pre-draw setup that requires an open window.
        function prepareToDrawInWindow(self)
        end
        
        % Draw() or not, depending on isVisible and possibly other factors.
        function mayDrawNow(self)
            if self.isVisible
                self.draw;
            end
        end
        
        % Subclass must redefine draw() to draw graphics.
        function draw(self)
        end
        
        % Shorthand to set isVisible=true.
        function show(self)
            self.isVisible = true;
        end
        
        % Shorthand to set isVisible=false.
        function hide(self)
            self.isVisible = false;
        end
    end
end